package com.example.wiki.controller;


import com.example.wiki.domain.CategorySaveReq;
import com.example.wiki.req.CategoryQueryReq;

import com.example.wiki.resp.CommonResp;
import com.example.wiki.resp.CategoryQueryResp;
import com.example.wiki.resp.PageResp;
import com.example.wiki.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "电子书分类")

@RestController
@RequestMapping("/category")
public class CategoryController {


    @Resource
    private CategoryService categoryService;


    @ApiOperation("获取所有的文档【分类】 分类名称 分类")
    @GetMapping("/all")
    public CommonResp all(){
        CommonResp<List<CategoryQueryResp>> resp = new CommonResp<>();

        List<CategoryQueryResp> list = categoryService.all();
        resp.setContent(list);
        resp.setMessage("请求电子书分类成功");
        return  resp;
    }
//@ApiOperation("获取部分分类 ")
//
//    @GetMapping("/list")
//    public CommonResp list(@Valid CategoryQueryReq req){
//        CommonResp<PageResp<CategoryQueryResp>> resp = new CommonResp<>();
//
//        PageResp<CategoryQueryResp> list = categoryService.list(req);
//        resp.setContent(list);
//        return  resp;
//    }

    @ApiOperation("保存分类  分类名称")
    @PostMapping("/save")
    public  CommonResp save(@Valid @RequestBody CategorySaveReq req){
        CommonResp resp = new CommonResp<>();
        categoryService.save(req);
        return  resp;
    }
    @ApiOperation("删除分类")
    @DeleteMapping("/delete/{id}")
    public  CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        categoryService.delete(id);
        return  resp;
    }





}
